<template>
  <div>
    
    <Group class="sender">
        <cell title="点击此编辑寄件人信息" :link="{path:'/Sender'}"  >
          <img slot="icon" width="15" style="display:block;margin-right:5px;" src="../assets/img/iconJi.png">
        </cell>
        <cell title="点击此编辑收件人信息" :link="{path:'/Receive'}"   class="lineOut">
          <img slot="icon" width="15" style="display:block;margin-right:5px;" src="../assets/img/iconSou.png">
        </cell>
    </Group >
    <Group class="sendSite">    
      <cell title="寄件站点" :link="{path:'/Sites'}"  >
        </cell>
    </Group>
    <Group class="exrpssSelect">    
      <cell title="快递公司选择" :link="{path:'/ExprssSelect'}"  >
        </cell>
    </Group>
    
    <Group class="payAction">
      <popup-radio title="付费方式" :options="options1" v-model="option1"></popup-radio>
    </Group>
    <Group class="sendSite">    
      <cell title="寄件站点"   >
        <span v-for="(item,$index) in weightList "  class="weightListItem" @click="selectWeight($index,item)" :class="[isshow===$index?'weightListItemOn':'']">{{item}}</span>  
        </cell>
    </Group>
    <Group class="goodsWeight">    
      <cell title="物品重量(kg)"   >
        <span class="add item" @click="add">+</span>
        <span class="num item">{{goodsWeightNum}}</span>
        <span class="reduce item" @click="reduce">-</span>
        </cell>
    </Group>
    <group class="beizhu">
        <x-textarea title="备注" v-model="beizhuText"></x-textarea>
    </group>
    <checklist :options="commonList" v-model="checklist002"  class="terms"></checklist>
    <div class="indexPage">
      <div class="left">
        预估: <span>${{price}}</span>
      </div>
      <div class="right" @click="payAction">下单</div>
    </div>  
  </div>
</template>

<script>
import { Group, Cell,Radio ,PopupRadio,TabItem,XTextarea,Checklist,Toast} from 'vux'
import store from '@/vuex/store'
export default {
  components: {
    Group,
    Cell,
    Radio,
    PopupRadio,
    TabItem,
    XTextarea,
    Checklist,
    Toast
  },
  data () {
    return {
      senderDate:{},
      // 付费方式
      option1: '',
      options1: ['寄付', '到付'],
      weightList:['文件','小件','大件','其他'],
      isshow:-1,
      weight:'',
      goodsWeightNum:1,
      beizhuText:'',
      checklist002:[],
      commonList:['同意《寄件服务条款》'],
      price:'00.00'
    }
  },
  methods:{
    change(value){
      console.log(value)
    },
    selectWeight($index,item){
      this.isshow =$index;
      this.weight = item;
      console.log(this.weight)
    },
    add(){
      var _this = this;
      this.goodsWeightNum+=1;
      var areId = _this.$store.state.receive.address[1];
      var exprssId = this.$store.state.express.id;
      var weightId = this.goodsWeightNum
      console.log(areId)
      console.log(exprssId)
      console.log(weightId)
      $.ajax({
        url:'http://bg.test.baimixu.cn/index.php?m=Home&c=SendApi&a=countCost',
        data:{id:exprssId,receiveCityId:areId,weight:weightId},
        type:'get',
        dataType:'jsonp',
        success(data){
          if(data.success){
            _this.price = data.d;
            console.log(_this.price)
          }else{
            _this.$vux.toast.show({
              text:"未对站点设置运费"
            })
              _this.goodsWeightNum = 1            
          }
        }
      })
    },
    reduce(){
      var _this = this;      
      if(this.goodsWeightNum<=1){
        return false;
      }else{
        this.goodsWeightNum-=1;
      }
      var areId = this.$store.state.sender.address[1];
      var exprssId = this.$store.state.express.id;
      var weightId = this.goodsWeightNum
      console.log(areId)
      console.log(exprssId)
      console.log(weightId)
      $.ajax({
        url:'http://bg.test.baimixu.cn/index.php?m=Home&c=SendApi&a=countCost',
        data:{id:exprssId,receiveCityId:areId,weight:weightId},
        type:'get',
        dataType:'jsonp',
        success(data){
          if(data.success){
            _this.price = data.d;
            console.log(_this.price)
          }
        }
      })
    },
    payAction(){
      console.log(1)
      var _this = this ;
   
      if(this.$store.state.sender === "" || this.$store.state.receive ==="" || this.$store.state.siteId === "" ||this.$store.state.express === ""){
       _this.$vux.toast.show({
          text:"信息填写不完整"
        })
      }else if(_this.option1 === ""){
        _this.$vux.toast.show({
          text:"请选择付款方式"
        })
      }else if(_this.weight === ""){
        _this.$vux.toast.show({
          text:"请选择文件类型"
        })
      }else if(_this.checklist002.length === 0){
        _this.$vux.toast.show({
          text:"请选择同意寄件服务条款"
        })
      }else{
        _this.$store.state.payInfo = _this.option1;
        console.log( _this.option1)
        $.ajax({
          url:'http://bg.test.baimixu.cn/index.php?m=Home&c=SendApi&a=addSend',
          data:{
            stationId:_this.$store.state.siteId,
            openId:1,
            sendName:_this.$store.state.sender.name,
            receiveName:_this.$store.state.receive.name,
            sendPhone:_this.$store.state.sender.phone,
            receivePhone:_this.$store.state.receive.phone,
            sendProvince:_this.$store.state.sender.address[0],
            sendPlace:_this.$store.state.sender.address[1],
            sendArea:_this.$store.state.sender.address[2],
            sendDeatilPlace:_this.$store.state.sender.info,
            receiveProvince:_this.$store.state.receive.address[0],
            receivePlace:_this.$store.state.receive.address[1],
            receiveArea:_this.$store.state.receive.address[2],
            receiveDetailPlace:_this.$store.state.receive.info,
            expressId:_this.$store.state.express.expressId,
            weight:_this.goodsWeightNum,
            money:_this.price,
            orderType:_this.weight,
            note:_this.beizhuText,
            payType:_this.option1
          },
          type:'get',
          dataType:'jsonp',
          success(data){
            _this.$store.state.allDate = data.d;
           _this.$store.commit('showUserName')
            _this.$router.push('Order')
          }
        })
      }
    }
  }, 
  // computed:{
  //   newPirce(){
  //     return this.price
  //   }
  // },
  created:function(){
      // console.log(this.$store.state[0])
      var openId = this.$wechat.config;
      console.log(openId)
      $.ajax({
        url:'http://wxtest.baimixu.cn/distApi.php?id=95',
        type:'get',
        dataType:'jsonp',
        success(data){
          console.log()
        }
      })
  },
  store

}
</script>
 